// $ANTLR 3.4 src/vb/week3/calc/CalcInterpreter.g 2012-05-25 16:21:46

package vb.week3.calc;
import java.util.Map;
import java.util.HashMap;
import java.lang.*;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

@SuppressWarnings({"all", "warnings", "unchecked"})
public class CalcInterpreter extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "BECOMES", "COLON", "COMMENT", "DIGIT", "DIVIDEBY", "DO", "ELSE", "EQUAL", "GREATEREQUAL", "GREATERTHAN", "IDENTIFIER", "IF", "INTEGER", "KOMMA", "LESSEQUAL", "LESSTHAN", "LETTER", "LOWER", "LPAREN", "MINUS", "NOTEQUAL", "NUMBER", "PLUS", "PRINT", "PROGRAM", "RPAREN", "SEMICOLON", "SWAP", "THEN", "TIMES", "UPPER", "VAR", "WHILE", "WS"
    };

    public static final int EOF=-1;
    public static final int BECOMES=4;
    public static final int COLON=5;
    public static final int COMMENT=6;
    public static final int DIGIT=7;
    public static final int DIVIDEBY=8;
    public static final int DO=9;
    public static final int ELSE=10;
    public static final int EQUAL=11;
    public static final int GREATEREQUAL=12;
    public static final int GREATERTHAN=13;
    public static final int IDENTIFIER=14;
    public static final int IF=15;
    public static final int INTEGER=16;
    public static final int KOMMA=17;
    public static final int LESSEQUAL=18;
    public static final int LESSTHAN=19;
    public static final int LETTER=20;
    public static final int LOWER=21;
    public static final int LPAREN=22;
    public static final int MINUS=23;
    public static final int NOTEQUAL=24;
    public static final int NUMBER=25;
    public static final int PLUS=26;
    public static final int PRINT=27;
    public static final int PROGRAM=28;
    public static final int RPAREN=29;
    public static final int SEMICOLON=30;
    public static final int SWAP=31;
    public static final int THEN=32;
    public static final int TIMES=33;
    public static final int UPPER=34;
    public static final int VAR=35;
    public static final int WHILE=36;
    public static final int WS=37;

    // delegates
    public TreeParser[] getDelegates() {
        return new TreeParser[] {};
    }

    // delegators


    public CalcInterpreter(TreeNodeStream input) {
        this(input, new RecognizerSharedState());
    }
    public CalcInterpreter(TreeNodeStream input, RecognizerSharedState state) {
        super(input, state);
    }

    public String[] getTokenNames() { return CalcInterpreter.tokenNames; }
    public String getGrammarFileName() { return "src/vb/week3/calc/CalcInterpreter.g"; }

     
        private Map<String,Integer> store = new HashMap<String,Integer>();   



    // $ANTLR start "program"
    // src/vb/week3/calc/CalcInterpreter.g:27:1: program : ^( PROGRAM ( declaration | statement )+ ) ;
    public final void program() throws RecognitionException {
        try {
            // src/vb/week3/calc/CalcInterpreter.g:28:5: ( ^( PROGRAM ( declaration | statement )+ ) )
            // src/vb/week3/calc/CalcInterpreter.g:28:9: ^( PROGRAM ( declaration | statement )+ )
            {
            match(input,PROGRAM,FOLLOW_PROGRAM_in_program94); 

            match(input, Token.DOWN, null); 
            // src/vb/week3/calc/CalcInterpreter.g:28:19: ( declaration | statement )+
            int cnt1=0;
            loop1:
            do {
                int alt1=3;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==VAR) ) {
                    alt1=1;
                }
                else if ( (LA1_0==BECOMES||(LA1_0 >= DIVIDEBY && LA1_0 <= DO)||(LA1_0 >= EQUAL && LA1_0 <= IF)||(LA1_0 >= LESSEQUAL && LA1_0 <= LESSTHAN)||(LA1_0 >= MINUS && LA1_0 <= PRINT)||LA1_0==SWAP||LA1_0==TIMES) ) {
                    alt1=2;
                }


                switch (alt1) {
            	case 1 :
            	    // src/vb/week3/calc/CalcInterpreter.g:28:20: declaration
            	    {
            	    pushFollow(FOLLOW_declaration_in_program97);
            	    declaration();

            	    state._fsp--;


            	    }
            	    break;
            	case 2 :
            	    // src/vb/week3/calc/CalcInterpreter.g:28:34: statement
            	    {
            	    pushFollow(FOLLOW_statement_in_program101);
            	    statement();

            	    state._fsp--;


            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);


            match(input, Token.UP, null); 


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "program"



    // $ANTLR start "declaration"
    // src/vb/week3/calc/CalcInterpreter.g:31:1: declaration : ^( VAR id= IDENTIFIER type ) ;
    public final void declaration() throws RecognitionException {
        CommonTree id=null;

        try {
            // src/vb/week3/calc/CalcInterpreter.g:32:5: ( ^( VAR id= IDENTIFIER type ) )
            // src/vb/week3/calc/CalcInterpreter.g:32:9: ^( VAR id= IDENTIFIER type )
            {
            match(input,VAR,FOLLOW_VAR_in_declaration128); 

            match(input, Token.DOWN, null); 
            id=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_declaration132); 

            pushFollow(FOLLOW_type_in_declaration134);
            type();

            state._fsp--;


            match(input, Token.UP, null); 


             store.put((id!=null?id.getText():null), 0); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "declaration"



    // $ANTLR start "statements"
    // src/vb/week3/calc/CalcInterpreter.g:36:1: statements : ( statement )+ ;
    public final void statements() throws RecognitionException {
        try {
            // src/vb/week3/calc/CalcInterpreter.g:37:5: ( ( statement )+ )
            // src/vb/week3/calc/CalcInterpreter.g:37:9: ( statement )+
            {
            // src/vb/week3/calc/CalcInterpreter.g:37:9: ( statement )+
            int cnt2=0;
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==BECOMES||(LA2_0 >= DIVIDEBY && LA2_0 <= DO)||(LA2_0 >= EQUAL && LA2_0 <= IF)||(LA2_0 >= LESSEQUAL && LA2_0 <= LESSTHAN)||(LA2_0 >= MINUS && LA2_0 <= PRINT)||LA2_0==SWAP||LA2_0==TIMES) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // src/vb/week3/calc/CalcInterpreter.g:37:9: statement
            	    {
            	    pushFollow(FOLLOW_statement_in_statements169);
            	    statement();

            	    state._fsp--;


            	    }
            	    break;

            	default :
            	    if ( cnt2 >= 1 ) break loop2;
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "statements"



    // $ANTLR start "statement"
    // src/vb/week3/calc/CalcInterpreter.g:40:1: statement : ( ^( PRINT v= compound_expr ) | ^( SWAP x= IDENTIFIER y= IDENTIFIER ) | compound_expr | dowhile_stat );
    public final void statement() throws RecognitionException {
        CommonTree x=null;
        CommonTree y=null;
        int v =0;


        try {
            // src/vb/week3/calc/CalcInterpreter.g:41:5: ( ^( PRINT v= compound_expr ) | ^( SWAP x= IDENTIFIER y= IDENTIFIER ) | compound_expr | dowhile_stat )
            int alt3=4;
            switch ( input.LA(1) ) {
            case PRINT:
                {
                alt3=1;
                }
                break;
            case SWAP:
                {
                alt3=2;
                }
                break;
            case BECOMES:
            case DIVIDEBY:
            case EQUAL:
            case GREATEREQUAL:
            case GREATERTHAN:
            case IDENTIFIER:
            case IF:
            case LESSEQUAL:
            case LESSTHAN:
            case MINUS:
            case NOTEQUAL:
            case NUMBER:
            case PLUS:
            case TIMES:
                {
                alt3=3;
                }
                break;
            case DO:
                {
                alt3=4;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 3, 0, input);

                throw nvae;

            }

            switch (alt3) {
                case 1 :
                    // src/vb/week3/calc/CalcInterpreter.g:41:9: ^( PRINT v= compound_expr )
                    {
                    match(input,PRINT,FOLLOW_PRINT_in_statement195); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_statement199);
                    v=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                     System.out.println("" + v);   

                    }
                    break;
                case 2 :
                    // src/vb/week3/calc/CalcInterpreter.g:43:9: ^( SWAP x= IDENTIFIER y= IDENTIFIER )
                    {
                    match(input,SWAP,FOLLOW_SWAP_in_statement225); 

                    match(input, Token.DOWN, null); 
                    x=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_statement229); 

                    y=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_statement233); 

                    match(input, Token.UP, null); 


                       
                                
                                int temp = store.get((x!=null?x.getText():null));
                                store.put((x!=null?x.getText():null),store.get((y!=null?y.getText():null)));
                                store.put((y!=null?y.getText():null),temp);
                                

                    }
                    break;
                case 3 :
                    // src/vb/week3/calc/CalcInterpreter.g:49:9: compound_expr
                    {
                    pushFollow(FOLLOW_compound_expr_in_statement245);
                    compound_expr();

                    state._fsp--;


                    }
                    break;
                case 4 :
                    // src/vb/week3/calc/CalcInterpreter.g:50:9: dowhile_stat
                    {
                    pushFollow(FOLLOW_dowhile_stat_in_statement255);
                    dowhile_stat();

                    state._fsp--;


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "statement"



    // $ANTLR start "dowhile_stat"
    // src/vb/week3/calc/CalcInterpreter.g:54:1: dowhile_stat : ^( DO statements WHILE v= compound_expr ) ;
    public final void dowhile_stat() throws RecognitionException {
        int v =0;


         int ix = input.index(); 
        try {
            // src/vb/week3/calc/CalcInterpreter.g:56:5: ( ^( DO statements WHILE v= compound_expr ) )
            // src/vb/week3/calc/CalcInterpreter.g:56:7: ^( DO statements WHILE v= compound_expr )
            {
            match(input,DO,FOLLOW_DO_in_dowhile_stat287); 

            match(input, Token.DOWN, null); 
            pushFollow(FOLLOW_statements_in_dowhile_stat289);
            statements();

            state._fsp--;


            match(input,WHILE,FOLLOW_WHILE_in_dowhile_stat291); 

            pushFollow(FOLLOW_compound_expr_in_dowhile_stat295);
            v=compound_expr();

            state._fsp--;


            match(input, Token.UP, null); 


             if (v != 0) { input.rewind(ix); }	      

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "dowhile_stat"



    // $ANTLR start "compound_expr"
    // src/vb/week3/calc/CalcInterpreter.g:59:1: compound_expr returns [int val = 0;] : ( ^( BECOMES id= IDENTIFIER v= compound_expr ) | ^( IF x= compound_expr y= compound_expr z= compound_expr ) | ^( LESSTHAN x= compound_expr y= compound_expr ) | ^( LESSEQUAL x= compound_expr y= compound_expr ) | ^( GREATERTHAN x= compound_expr y= compound_expr ) | ^( GREATEREQUAL x= compound_expr y= compound_expr ) | ^( EQUAL x= compound_expr y= compound_expr ) | ^( NOTEQUAL x= compound_expr y= compound_expr ) | ^( PLUS x= compound_expr y= compound_expr ) | ^( MINUS x= compound_expr y= compound_expr ) | ^( TIMES x= compound_expr y= compound_expr ) | ^( DIVIDEBY x= compound_expr y= compound_expr ) |z= operand );
    public final int compound_expr() throws RecognitionException {
        int val =  0;;


        CommonTree id=null;
        int v =0;

        int x =0;

        int y =0;

        int z =0;


        try {
            // src/vb/week3/calc/CalcInterpreter.g:60:5: ( ^( BECOMES id= IDENTIFIER v= compound_expr ) | ^( IF x= compound_expr y= compound_expr z= compound_expr ) | ^( LESSTHAN x= compound_expr y= compound_expr ) | ^( LESSEQUAL x= compound_expr y= compound_expr ) | ^( GREATERTHAN x= compound_expr y= compound_expr ) | ^( GREATEREQUAL x= compound_expr y= compound_expr ) | ^( EQUAL x= compound_expr y= compound_expr ) | ^( NOTEQUAL x= compound_expr y= compound_expr ) | ^( PLUS x= compound_expr y= compound_expr ) | ^( MINUS x= compound_expr y= compound_expr ) | ^( TIMES x= compound_expr y= compound_expr ) | ^( DIVIDEBY x= compound_expr y= compound_expr ) |z= operand )
            int alt4=13;
            switch ( input.LA(1) ) {
            case BECOMES:
                {
                alt4=1;
                }
                break;
            case IF:
                {
                alt4=2;
                }
                break;
            case LESSTHAN:
                {
                alt4=3;
                }
                break;
            case LESSEQUAL:
                {
                alt4=4;
                }
                break;
            case GREATERTHAN:
                {
                alt4=5;
                }
                break;
            case GREATEREQUAL:
                {
                alt4=6;
                }
                break;
            case EQUAL:
                {
                alt4=7;
                }
                break;
            case NOTEQUAL:
                {
                alt4=8;
                }
                break;
            case PLUS:
                {
                alt4=9;
                }
                break;
            case MINUS:
                {
                alt4=10;
                }
                break;
            case TIMES:
                {
                alt4=11;
                }
                break;
            case DIVIDEBY:
                {
                alt4=12;
                }
                break;
            case IDENTIFIER:
            case NUMBER:
                {
                alt4=13;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;

            }

            switch (alt4) {
                case 1 :
                    // src/vb/week3/calc/CalcInterpreter.g:60:9: ^( BECOMES id= IDENTIFIER v= compound_expr )
                    {
                    match(input,BECOMES,FOLLOW_BECOMES_in_compound_expr329); 

                    match(input, Token.DOWN, null); 
                    id=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_compound_expr333); 

                    pushFollow(FOLLOW_compound_expr_in_compound_expr337);
                    v=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                     val = v; store.put((id!=null?id.getText():null), v); 

                    }
                    break;
                case 2 :
                    // src/vb/week3/calc/CalcInterpreter.g:61:9: ^( IF x= compound_expr y= compound_expr z= compound_expr )
                    {
                    match(input,IF,FOLLOW_IF_in_compound_expr353); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr357);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr361);
                    y=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr365);
                    z=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    if(x!=0){val = y;} else{val = z;}

                    }
                    break;
                case 3 :
                    // src/vb/week3/calc/CalcInterpreter.g:62:9: ^( LESSTHAN x= compound_expr y= compound_expr )
                    {
                    match(input,LESSTHAN,FOLLOW_LESSTHAN_in_compound_expr380); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr384);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr388);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    if(x<y)  {val = 1;}  else{val = 0;}

                    }
                    break;
                case 4 :
                    // src/vb/week3/calc/CalcInterpreter.g:63:9: ^( LESSEQUAL x= compound_expr y= compound_expr )
                    {
                    match(input,LESSEQUAL,FOLLOW_LESSEQUAL_in_compound_expr406); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr410);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr414);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    if(x<=y) {val = 1;}  else{val = 0;}

                    }
                    break;
                case 5 :
                    // src/vb/week3/calc/CalcInterpreter.g:64:9: ^( GREATERTHAN x= compound_expr y= compound_expr )
                    {
                    match(input,GREATERTHAN,FOLLOW_GREATERTHAN_in_compound_expr431); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr435);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr439);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    if(x>y)  {val = 1;}  else{val = 0;}

                    }
                    break;
                case 6 :
                    // src/vb/week3/calc/CalcInterpreter.g:65:9: ^( GREATEREQUAL x= compound_expr y= compound_expr )
                    {
                    match(input,GREATEREQUAL,FOLLOW_GREATEREQUAL_in_compound_expr454); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr458);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr462);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    if(x>=y) {val = 1;}  else{val = 0;}

                    }
                    break;
                case 7 :
                    // src/vb/week3/calc/CalcInterpreter.g:66:9: ^( EQUAL x= compound_expr y= compound_expr )
                    {
                    match(input,EQUAL,FOLLOW_EQUAL_in_compound_expr476); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr480);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr484);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    if(x==y) {val = 1;}  else{val = 0;}

                    }
                    break;
                case 8 :
                    // src/vb/week3/calc/CalcInterpreter.g:67:9: ^( NOTEQUAL x= compound_expr y= compound_expr )
                    {
                    match(input,NOTEQUAL,FOLLOW_NOTEQUAL_in_compound_expr505); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr509);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr513);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                    if(x!=y) {val = 1;}  else{val = 0;}

                    }
                    break;
                case 9 :
                    // src/vb/week3/calc/CalcInterpreter.g:68:9: ^( PLUS x= compound_expr y= compound_expr )
                    {
                    match(input,PLUS,FOLLOW_PLUS_in_compound_expr531); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr535);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr539);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                     val = x + y;  

                    }
                    break;
                case 10 :
                    // src/vb/week3/calc/CalcInterpreter.g:69:9: ^( MINUS x= compound_expr y= compound_expr )
                    {
                    match(input,MINUS,FOLLOW_MINUS_in_compound_expr556); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr560);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr564);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                     val = x - y;  

                    }
                    break;
                case 11 :
                    // src/vb/week3/calc/CalcInterpreter.g:70:9: ^( TIMES x= compound_expr y= compound_expr )
                    {
                    match(input,TIMES,FOLLOW_TIMES_in_compound_expr580); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr584);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr588);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                     val = x * y;  

                    }
                    break;
                case 12 :
                    // src/vb/week3/calc/CalcInterpreter.g:71:9: ^( DIVIDEBY x= compound_expr y= compound_expr )
                    {
                    match(input,DIVIDEBY,FOLLOW_DIVIDEBY_in_compound_expr606); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_compound_expr_in_compound_expr610);
                    x=compound_expr();

                    state._fsp--;


                    pushFollow(FOLLOW_compound_expr_in_compound_expr614);
                    y=compound_expr();

                    state._fsp--;


                    match(input, Token.UP, null); 


                     // System.out.println("/ " + x + " " + y); 
                                                            if(y == 0)
                                                              throw new IllegalArgumentException("Divide by zero not allowed");
                                                            val = x / y;
                                                          

                    }
                    break;
                case 13 :
                    // src/vb/week3/calc/CalcInterpreter.g:76:9: z= operand
                    {
                    pushFollow(FOLLOW_operand_in_compound_expr629);
                    z=operand();

                    state._fsp--;


                     val = z;      

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return val;
    }
    // $ANTLR end "compound_expr"



    // $ANTLR start "operand"
    // src/vb/week3/calc/CalcInterpreter.g:79:1: operand returns [int val = 0] : (id= IDENTIFIER |n= NUMBER );
    public final int operand() throws RecognitionException {
        int val =  0;


        CommonTree id=null;
        CommonTree n=null;

        try {
            // src/vb/week3/calc/CalcInterpreter.g:80:5: (id= IDENTIFIER |n= NUMBER )
            int alt5=2;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==IDENTIFIER) ) {
                alt5=1;
            }
            else if ( (LA5_0==NUMBER) ) {
                alt5=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;

            }
            switch (alt5) {
                case 1 :
                    // src/vb/week3/calc/CalcInterpreter.g:80:9: id= IDENTIFIER
                    {
                    id=(CommonTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_operand680); 

                     val = store.get((id!=null?id.getText():null));       

                    }
                    break;
                case 2 :
                    // src/vb/week3/calc/CalcInterpreter.g:81:9: n= NUMBER
                    {
                    n=(CommonTree)match(input,NUMBER,FOLLOW_NUMBER_in_operand697); 

                     val = Integer.parseInt((n!=null?n.getText():null)); 

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return val;
    }
    // $ANTLR end "operand"



    // $ANTLR start "type"
    // src/vb/week3/calc/CalcInterpreter.g:84:1: type : INTEGER ;
    public final void type() throws RecognitionException {
        try {
            // src/vb/week3/calc/CalcInterpreter.g:85:5: ( INTEGER )
            // src/vb/week3/calc/CalcInterpreter.g:85:9: INTEGER
            {
            match(input,INTEGER,FOLLOW_INTEGER_in_type729); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "type"

    // Delegated rules


 

    public static final BitSet FOLLOW_PROGRAM_in_program94 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_declaration_in_program97 = new BitSet(new long[]{0x0000000A8F8CFB18L});
    public static final BitSet FOLLOW_statement_in_program101 = new BitSet(new long[]{0x0000000A8F8CFB18L});
    public static final BitSet FOLLOW_VAR_in_declaration128 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_declaration132 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_type_in_declaration134 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_statement_in_statements169 = new BitSet(new long[]{0x000000028F8CFB12L});
    public static final BitSet FOLLOW_PRINT_in_statement195 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_statement199 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_SWAP_in_statement225 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_statement229 = new BitSet(new long[]{0x0000000000004000L});
    public static final BitSet FOLLOW_IDENTIFIER_in_statement233 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_compound_expr_in_statement245 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_dowhile_stat_in_statement255 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_DO_in_dowhile_stat287 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_statements_in_dowhile_stat289 = new BitSet(new long[]{0x0000001000000000L});
    public static final BitSet FOLLOW_WHILE_in_dowhile_stat291 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_dowhile_stat295 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_BECOMES_in_compound_expr329 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_compound_expr333 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr337 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_IF_in_compound_expr353 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr357 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr361 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr365 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_LESSTHAN_in_compound_expr380 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr384 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr388 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_LESSEQUAL_in_compound_expr406 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr410 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr414 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_GREATERTHAN_in_compound_expr431 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr435 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr439 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_GREATEREQUAL_in_compound_expr454 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr458 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr462 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_EQUAL_in_compound_expr476 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr480 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr484 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_NOTEQUAL_in_compound_expr505 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr509 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr513 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_PLUS_in_compound_expr531 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr535 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr539 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_MINUS_in_compound_expr556 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr560 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr564 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_TIMES_in_compound_expr580 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr584 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr588 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_DIVIDEBY_in_compound_expr606 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr610 = new BitSet(new long[]{0x00000002078CF910L});
    public static final BitSet FOLLOW_compound_expr_in_compound_expr614 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_operand_in_compound_expr629 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IDENTIFIER_in_operand680 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_NUMBER_in_operand697 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INTEGER_in_type729 = new BitSet(new long[]{0x0000000000000002L});

}